Post Effects/ Post shading

Post Shading

Tutorial level: Advanced

Example project: 'samples/v5samples/post shading studio'.

In this tutorial we will examine how to collect channel information from the ray tracer in order to evaluate the basic illumination model in the post processing phase. Post processed surface shading has some advantages:

  • Sampled illumination data can be filtered before the shading. This reduces noise.
  • Recomputing the post shading after illumination parameter adjustments is often quicker than rendering the image from scratch. The speed advantage is remarkable when the scene geometry is complex and slow to ray trace.

The illumination model of Realsoft 3D - and the rendering pipeline in general - is open and customizable. This means that the parameters of a post shading system are not fixed. The user can any time code a new VSL material, which changes surface illumination in a totally new way. It's impossible to reproduce the functionality of the new shader accurately in a post shading system, which assumes other kind of shading behavior.

A simple post shading system renders very quickly and allows interactive adjusting of parameters. A complex post shading solution which controls the result image in a detailed manner - providing even object or light source specific parameters - is slower to use, but naturally provides much more possibilities to adjust the image. The optimal choice between speed and flexibility depends on each scene.

The standard setup of Realsoft 3D includes a set of example components for post shading. These components allow quite a detailed control over post shading. The components are built using the standard VSL objects and post effects, and therefore they can be modified and tailored to suit all kind of projects. For example, unused elements can be deleted to speed up rendering.


Post Shading Example

Let's experiment how to use the post shading system, which is included in the program setup.

1. Model first a test scene: a semi-reflective floor surface, a glass object over the floor, a mirror object, etc. Feel free to use your imagination. Add a couple of point lights or spotlights to the scene. In the property window, set the Quality slider of the light sources to the value 1. This is the minimal value, which turns light sampling over a spherical light source volume on. If you test render an image, shadows will show clearly visible sampling noise. Turn also view's flashlight off, because the post shading system includes its own independent flashlight.


The test scene. Shadows are noisy because of minimal area light sampling.

2. Go to the material tab of the select window. Choose New/From Template from the popup menu of the select window. Use the opened file browser to find and load in the material 'realsoft3d/materials/illumination/capture channels'. Deselect all geometry objects (for example: activate the view and hit Ctrl+t). Then drag and drop the loaded material 'capture_channels' to the view window. This maps the shader to the root level of the scene. Shading information of all objects will be collected.


The channel capture shader mapped to the root level

3. Switch to the render settings tab of the select window. Using the property window, set the antialiasing level of the render settings object, which you plan to use (for example reasonable quality), to zero. The post shading system cannot afterwards separate illumination components from antialiased pixels, and therefore ray tracer antialiasing would cause shading errors. Antialiasing must be done after the post processing by down scaling the image resolution.

4. Go to the post image effects tab of the select window. Open the popup menu and choose Paste from a File. Load in the file 'realsoft3d/posteffects/post_shading'. Drag and drop either post_shading or post_shading_draft from the select window into the view window. The draft version does not use supersampled resolution to antialiase and is therefore 4 times faster.

5. Open the popup menu of the view window and select Ray Trace+Backup.


Set image effects to post_shading_draft using drag and drop and apply Ray Trace+Backup

Fist the ray traced image appears, then, after a while, a post-shaded version. The post shaded version looks quite similar to the original image, except that the dithered shadows are now smooth.


Shadow quality improved

The next step is to experiment with the post shading parameters. Switch to the post image effects tab of the select window, and open the property window.

6. To make reflections sharper, select the blur_reflection effect and decrease the Blur Level value using the property window. Then select Render/Post Process from the view popup menu. A new image appears much quicker, because ray tracing was not computed.

7. To make shadows even smoother, select the blur_shadows effect. Increase either the Blur Level value or the Iterations value. Then apply Render/Post Process.

8. To remove all reflections from surfaces, select the evaluate_shading effect and set Reflection Weight to black (0,0,0). Then apply Render/Post Process.

9. Change the Flashlight value of the evaluate_shading effect to pale yellow (0.8, 0.8, 0.6). Post process again. The image gets a warm fill light effect

10. Set Specularity Weight to (1.6 1.1 1.1), then Post Process. Specular highlights become brighter and get a red tone around the white brightness maximum.


Post shading parameters

As the experiments above show, the most important component of the system is the evaluate_shading effect. It is a VSL effect, which weights the stored channels and then recombines them to a new image. The VSL structure of the effect is quite straightforward and easy to customize. By default, all weights are set to the level (1,1,1), which reproduces the original ray traced illumination. Note, that although the weights are presented as RGB colors, their range is not limited to 0..1 interval. The full list of shading parameters is explained below.

  • Diffuse Weight: rescales the usual diffuse shading. This is the most common shading component.
  • Ambient Weight: controls self-illumination of surfaces (not the illumination by ambient lights).
  • Fog Weight: the weight for a global fog.
  • Reflection Weight: controls mirror reflections.
  • Transparency Weight: controls optical transparency i.e. refracted rays (not faded surfaces).
  • Specularity Weight: the weight for all non-diffuse illumination components from light sources. Specular highlights, ambient lighting and user defined Surface Illumination shaders contribute trough this parameter.
  • Flashlight: the fill light from the camera. Replaces (not rescales) the camera flash light.

It should be noted that these parameters control only the first step of the recursive ray tracing. For the sake of speed and memory consumption, the system stores the channel values only from the first step of the ray trace recursion. For example, a self-illuminated surface which is seen in a mirror reflection does not become darker when you decrease the ambient weight. Instead, the reflection weight controls its appearance.

The fog blurring effect, which is part of the post shading system, needs some special attention. With it, you can reduce the sampling noise of volume sampled fog shaders. Applying a pixel accurate fog shader to blurred shading components sometimes creates clearly visible errors. You can compensate this by making fog blurring as large as the maximum of the other blur components, such as the shadow blur effect.


Foggy atmosphere before and after post effect blurring

Let's take a closer look at the channel capture material. Go to the material tab of the select window, make sure that the material capture_channels is selected and open the property window. The material interface displays a large number of switches 'XXX Capture Off'. With these switches, you can turn off collection of unused data and consequently speed up rendering. By default, all channels used by the post effect shading are enabled.


The channel capture controls

This material can be used in collecting information for all kinds of post processing purposes. The switches and their relation to underlying channels are:

  • Diffuse Capture Off: do not capture diffuse color to bt_diffuse_color channel.
  • Ambient Capture Off: do not capture self-illumination of surfaces to bt_ambient channel.
  • Diffuse Shading Capture Off: do not capture diffuse shading by light sources to bt_dissuse_shading channel.
  • Specular Shading Capture Off: do not capture non-diffuse shading by light sources (specular, ambient light, user defined illumination shaders) to bt_specularity channel.
  • Light Capture Off: do not capture the unshadowed light from light sources to bt_light channel.
  • Shadow Capture Off: do not capture the amount of shadow to bt_shadow channel.
  • Fade Capture Off: do not capture 1-Fade value to bt_fade channel.
  • Ray Capture Off: do not capture reflections to bt_reflection and transparency to bt_transparency channel.
  • Fog Capture Off: do not capture effect of a global fog to bt_total channel.
  • Distance Capture Off: do not capture distance (z buffer) to bt_depth channel.

Some important notes:

  • Ambient Capture means capturing of self-illuminating materials, not ambient light sources.
  • Specular Shading Capture collects all non-diffuse illumination elements. For example, ambient lights are included here. The name is chosen like this because specular highlights are probably the most common illumination effect in this category.
  • By enabling Shadow Capture, you can output the bt_shadow channel into a shadow mask file.
  • Fade Capture computes 1-fade to the bt_fade channel. This is a suitable value for the alpha channel output. However, note that empty space area gets a full alpha value 1.0, unless you add a backdrop plane to the scene.
  • Distance Capture computes a non-linear curve controlled z buffer value. Distances from 0 to infinity are mapped to the 0..1 interval, which means that the z buffer does not overflow or truncate the values regardless of the used datatype (byte, word, float etc.).
  • Fog Capture stores the effect of a global atmospheric fog (which surrounds the camera) for post shading. It does not capture anything from local fog clouds or other gaseous objects, which do not enclose the camera. The reason is that the post shading system recomputes only the first recursion step of ray racing.

The idea behind the capture_channels material is that in includes all surface related shaders. In each shader, the material examines how the total illumination and other relevant channels change and stores the observed changes to a set of additional channels bt_diffuse, bt_ambient, etc. As explained earlier in this tutorial, only the first step of ray trace recursion is stored.